package com.itheima.d2_Collection_List;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * List特有的遍历方式
 */
public class demo2 {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();//注意：类型需要指定为List类型，否则后面无法使用独有的add方法
        list.add("赵");
        list.add("钱");
        list.add("孙");
        list.add("李");
        
        //1.for
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }
        //2.迭代器
        Iterator<String> it = list.listIterator();//ctrl+alt+v自动补全
        while (it.hasNext()){
            String ele = it.next();
            System.out.println(ele);
        }
        //3.foreach
        for (String s : list) {
            System.out.println(s);
        }
        //4.Lambda
        list.forEach(s -> {
            System.out.println(s);
        });
    }
}
